<?php defined('SYSPATH') or die('No direct script access.');

/**
 * Enter description here...
 *
 * @package    	Kohadmin
 * @subpackage	Templates
 * @author     	Thomas Filius
 * @copyright  	(c) 2009 Nobis Stultius IT
 * @license		GNU Lesser General Public License 3
 * @version		$Id $
 */?>

<div id="kohadminindex">
	<?php echo (isset($filter)) ? $filter : ""; ?>
	
	<?php echo (isset($title)) ? "<h3>".$title."</h3>" : ""; ?>

	<table class="<?=$table_class?>">
		<thead>
			<tr>
			<?php foreach ($descriptors as $descriptor) {
				echo '<th ';
				echo (empty($descriptor['class'])) ? "" : 'class="'.$descriptor['class'].'"';
				echo '>'.$descriptor['name'].'</th>';
			} ?>
			</tr>
		</thead>

		<tbody>
		<?php
			if (count($rows) > 0) {
				foreach ($rows as $row) {
					echo '<tr>';
					foreach ($row as $field) {
						echo '<td>';
						if (! empty($field['action'])) {
							echo html::anchor($field['action'], $field['value']);
						} else {
							echo $field['value'];
						}
						echo '</td>';
					}
					echo '</tr>';
				}
			} else {
				echo '<tr><td colspan='.count($descriptors).'>'.Kohana::lang('kohadminindex.noresults').'</td></tr>';
			}
		?>
		</tbody>
	</table>
</div>

<script type="text/javascript">
	jQuery(document).ready( function() {
		/**
		 * Filter
		 */
		jQuery("#kohadminindex input.query").addClass("idle");

		jQuery('#kohadminindex input.query').focus( function() {
			jQuery(this).removeClass("idle").addClass("focus");

			if (this.value == this.defaultValue){
				this.value = '';
			}
			if(this.value != this.defaultValue){
				this.select();
			}
		});
		jQuery('#kohadminindex input.query').blur( function() {
			if (jQuery.trim(this.value) == ""){
				Query(this).removeClass("focus").addClass("idle");
				this.value = (this.defaultValue ? this.defaultValue : "");
			}
		});

		/**
		 * Table body
		 */
		jQuery("#kohadminindex table.sortable").tablesorter();
		jQuery("#kohadminindex table tr").hover(
			function() {
				jQuery(this).find('td').addClass('focus');
			},
			function() {
				jQuery(this).find('td').removeClass('focus');
			}
		);
	});
</script>
